package vo.community
{
	import cultu.community.message.Community;
	
	import mx.collections.ArrayCollection;

	public class CommunityVO
	{
		/**le vo source*/
		public var srcCommunity:Community;
		
		/**stratégie d'ajout des enfant*/
		private var _strategy:CommunityStrategy;
		
		public var fake:Boolean;
		
		public function CommunityVO(o:Community,pFake:Boolean=false)
		{
			fake = pFake;
			
			if(o)
			{
				srcCommunity = o;
			}
			else
			{
				srcCommunity = new Community();
			}
			
			defineStrategy();
		}
		
		private function get strategy():CommunityStrategy
		{
			if(!_strategy)
				defineStrategy();
			
			return _strategy;
		}
		
		/**ajout d'un enfant via ma strategy*/
		public function addChild(pCommunity:CommunityVO):void
		{
			if(strategy)
				strategy.addChild(pCommunity);
		}
		
		/**suppression d'un enfant via ma strategy*/
		public function removeChild(pCommunity:CommunityVO):void
		{
			if(strategy)
				strategy.removeChild(pCommunity);
		}
		
		/**définition de ma stratégie en fonction du type de communauté*/
		private function defineStrategy():void
		{
			if(isUniverse())
				_strategy = new CommunityUniverseStrategy();
			
			if(isCategory())
				_strategy = new CommunityCategoryStrategy();
			
			if(isFamily())
				_strategy = new CommunityFamilyStrategy();
		}
		
		/**accesseur sur les enfants*/
		public function get children():ArrayCollection
		{
			if(strategy)
				return _strategy.children;
			
			return null;
		}
		
		/**est ce que j'ai des enfants*/
		public function hasChildren():Boolean
		{
			return children != null && children.length > 0;
		}
		
		/** communauté est une commauté de type univers ?*/
		public function isUniverse():Boolean
		{
			return universe && !category && !family && !kind;
		}
		
		/** communauté est une commauté de type catgorie ?*/
		public function isCategory():Boolean
		{
			return universe && category && !family && !kind; 
		}
		
		/** communauté est une commauté de type famille ?*/
		public function isFamily():Boolean
		{
			return universe && category && family && !kind;
		}
		
		/** communauté est une commauté de type genre ?*/
		public function isKind():Boolean
		{
			return universe && category && family && kind;
		}
		
		/**getter universe*/
		public function get universe():String
		{
			return srcCommunity.universe;
		}
		
		/**getter category*/
		public function get category():String
		{
			return srcCommunity.category;
		}
		
		/**getter family*/
		public function get family():String
		{
			return srcCommunity.family;
		}
		
		/**getter kind*/
		public function get kind():String
		{
			return srcCommunity.kind;
		}
		
		/**setter universe*/
		public function set universe(value:String):void
		{
			if(value != universe)
				srcCommunity.universe = value;
		}
		
		/**setter catégorie*/
		public function set category(value:String):void
		{
			if(value != category)
				srcCommunity.category = value;
		}
		
		/**setter family*/
		public function set family(value:String):void
		{
			if(value != family)
				srcCommunity.family = value;
		}
		
		/**setter kind*/
		public function set kind(value:String):void
		{
			if(value != kind)
				srcCommunity.kind = value;
		}
		
		/**getter color universe*/
		public function get color():uint
		{
			if(srcCommunity.universeColor)
			{
				return uint('0x'+srcCommunity.universeColor);
			}
			
			return 0xffffff;
		}
		
		/**le label de la communauté en fonction de ce qu'elle est*/
		public function get label():String
		{
			if(isUniverse())
				return universe;
			if(isFamily())
				return family;
			if(isCategory())
				return category;
			if(isKind())
				return kind;
			
			return ' ';
		}
		
		/**le level de la communauté en fonction de son type*/
		public function get level():int
		{
			if(isUniverse())
				return 0;
			if(isFamily())
				return 2;
			if(isCategory())
				return 1;
			if(isKind())
				return 3;
			
			return -1;
		}
		
		/**setter color universe*/
		public function set universeColor(value:String):void
		{
			if(value != srcCommunity.universeColor)
				srcCommunity.universeColor = value;
		}
		
		/**getter icone*/
		public function get icon():String
		{
			return srcCommunity.universeIcon;
		}
		
		/**getter icone*/
		public function set icon(pValue:String):void
		{
			if(pValue != icon)
				srcCommunity.universeIcon = pValue;
		}
		
		/**equals*/
		public function equals(pCom:CommunityVO):Boolean
		{
			return pCom.universe == universe && 
				pCom.category == category && 
				pCom.family == family && 
				pCom.kind == kind;
		}
	}
}